//
//  EmptyViewController.m
//  WisdomZhuHai
//
//  Created by JasonLee on 15/1/22.
//  Copyright (c) 2015年 wyd. All rights reserved.
//

#import "EmptyViewController.h"
#import "TransforController.h"
#import "QRCodeGenerator.h"


@interface EmptyViewController () <UISearchBarDelegate>

@property (nonatomic, strong)UISearchBar* searchBar;

@end

@implementation EmptyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    if (_isSearch == true) {
        [self configureSearchBar];
        [self.view addSubview:[TransforController shardeInstanceOfNavigationBarAndStatusBarCoverViewWithY:0 andTitle:@"全局搜索"]];
        [self.view addSubview:self.searchBar];
        [self makeShadow];
    }
    if (_isOKCoupon == true) {
        [self setupQRCode];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - shadow

- (void)makeShadow {
    UIView *shadow = [[UIView alloc] initWithFrame:CGRectMake(0, 105, self.view.bounds.size.width, self.view.bounds.size.height - 60)];
    shadow.backgroundColor = [UIColor blackColor];
    shadow.alpha = 0.5;
    shadow.tag = 10000;
    UILabel *cancelLab = [[UILabel alloc] initWithFrame:CGRectMake(90, 150, 140, 20)];
    cancelLab.textAlignment = UITextAlignmentCenter;
    cancelLab.textColor = [Common colorWithRGB:0xcccccc];
    cancelLab.alpha = 0.2;
    cancelLab.font = [UIFont fontWithName:@"Arial" size:15.0];
    cancelLab.text = @"点击取消返回上一页";
    [shadow addSubview:cancelLab];
    [self.view addSubview:shadow];
}

- (void)setupQRCode {
    UIImageView *QRcodeView = [[UIImageView alloc] initWithFrame:CGRectMake(55, 100, 200, 200)];
    UIImage *image = [QRCodeGenerator qrImageForString:self.OKCoupon imageSize:QRcodeView.bounds.size.width];
    QRcodeView.image = image;
    [self.view addSubview:QRcodeView];
}

#pragma mark - Configuration

- (void)configureSearchBar {
    self.searchBar = [[UISearchBar alloc] initWithFrame: CGRectMake(0.0, 65, self.view.bounds.size.width, 40)];
    self.searchBar.showsCancelButton = YES;
    self.searchBar.delegate = self;
    self.searchBar.keyboardType = UIKeyboardTypeDefault;
}

#pragma mark - UISearchBarDelegate

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
    NSLog(@"The default search bar keyboard search button was tapped: %@.", searchBar.text);
    [searchBar resignFirstResponder];
    [self dismissViewControllerAnimated:YES completion:nil];
    [self.searchDelegate globalSearchCell:searchBar.text];
}

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
    NSLog(@"The default search bar cancel button was tapped.");
    
    [searchBar resignFirstResponder];
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
